﻿int year = 2022;                                //可改变年份
DateTime date = new DateTime(year, 1, 1);
int x, y = 0;
do
{
    x = (date.Month - 1) % 3 * 40;              
    if (date.Day == 1)                          //每一月份的循环
    {
        x = (date.Month - 1) % 3 * 40;          //控制列
        y = (date.Month - 1) / 3 * 15;          //控制行
        Console.SetCursorPosition(x, y);
        Console.Write($"{date.Month}月");
        Console.SetCursorPosition(x, y += 1);
        Console.Write("日  一  二  三  四  五  六");
        Console.SetCursorPosition(x, y += 1);
        int dayofweek = (int)date.DayOfWeek;    //判断每一月的一号是星期几
        Console.Write(new String(' ', 4 * dayofweek));
    }
    Console.Write(date.Day);                    //打印日期
    if (date.Day < 10)                          //控制格式（空格）
        Console.Write(new String(' ', 3));
    else
        Console.Write(new String(' ', 2));
    if ((int)date.DayOfWeek == 6)               //到了星期六则换行
    {
        Console.SetCursorPosition(x, y += 1);
    }
    date = date.AddDays(1);                     
} while (date.Year == year);